import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { FormBuilder, Validators } from '@angular/forms';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { ApiService } from 'src/app/core/api';
import { MessageService } from 'src/app/core/service/message.service';
import { DatePipe } from '@angular/common';
 
/**
 * 首页
 */

@Component({
    templateUrl: './index.html',
    styleUrls: ['./index.scss'],
})
export class GGAddComponent implements OnInit {
    validateForm;
    ngOnInit() {
        this.validateForm = this.fb.group({
            title: [null, [Validators.required]],
            content: [null, [Validators.required]]
        });
    }
    constructor(
        private router: Router,
        private fb: FormBuilder,
        private apiService: ApiService,
        private message: MessageService,
        private nzMessageService: NzMessageService,
        private modal: NzModalService,
        private datePipe:DatePipe
    ) { }
    submit(data ,type) {
        data.active = type;
        if (this.validateForm.valid) {
            this.apiService.post('创建公告', data).then((res: any) => {
                this.router.navigate(['/home/index']);
            })
        } else {
            this.nzMessageService.error('请正确填写表单后提交')
        }
    }
}
